version: '3.9'

services:
  postgres_db_deploy:
    container_name: postgres_db_deploy
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DBNAME}
      PGPORT: ${DB_PORT}
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - ${DB_PORT}:${DB_PORT}
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres -d postgres" ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
  back:
    restart: always
    container_name: back
    build:
      context: ./
      dockerfile: Dockerfile
    environment:
      SPRING_PORT: ${SPRING_PORT}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_USERNAME: ${DB_USERNAME}
      DB_DBNAME: ${DB_DBNAME}
      DB_PORT: ${DB_PORT}
      DB_HOSTNAME: "postgres_db_deploy"
      PING_MESSAGE: "From Docker"
    ports:
      - ${SPRING_PORT}:${SPRING_PORT}
    #    command: [ "java", "-jar"]
    depends_on:
      postgres_db_deploy:
        condition: service_healthy
  front:
    restart: always
    container_name: front
    build:
      context: ./front
      dockerfile: Dockerfile
    environment:
      PORT: ${REACT_PORT}
      SPRING_PORT: ${SPRING_PORT}
      SPRING_HOSTNAME: ${SPRING_HOSTNAME}
    ports:
      - ${REACT_PORT}:${REACT_PORT}
    depends_on:
      postgres_db_deploy:
        condition: service_healthy